function bridge_new(new_bridge, DFILE)
% compute a new balanced waveform and display it
% small changes, 8/16/05 P. Manis.
global ALLCH
global CONTROL
global BRIDGE

if(isempty(new_bridge))
   return;
end;

VOLTAGE=ALLCH{1};
CURRENT=ALLCH{2};

h=findobj('Tag', 'CTL');
if(~ishandle(h))
    return;
end
sel = get(h, 'Value'); % read control entry that is selected...

step_time = number_arg(CONTROL(sel).durho);
min_tview = step_time-2*BRIDGE.factor;
if(min_tview < 0) min_tview = 0;
end;
max_tview = step_time+5*BRIDGE.factor;
maxtdata = max(max(make_time(DFILE)));
if(max_tview > maxtdata)
    max_tview = maxtdata;
end;

RATES = DFILE.rate.*DFILE.nr_channel/1000;
tbeg = min_tview./RATES;
tend = max_tview./RATES; 
tstep = step_time./RATES;
npts = size(VOLTAGE);
for i = 1:length(DFILE.record)
	t0 = floor(tbeg(i));
    if(t0 < 1) t0 = 1; end;
	t1 = floor(tend(i));
    if(t1 > size(VOLTAGE,2)) t1 = size(VOLTAGE,2); end;
	ts = floor(tstep(i));
	v_bal(i,:) = VOLTAGE(i,t0:t1)-CURRENT(i,t0:t1)*new_bridge/1000;
	v_bal(i,ts-t0+1)=NaN;
	time(i,:)=min_tview:RATES(i):(max_tview);
	tmax = max(max(time));
	time(i, ts-t0+1)=NaN;
end;
% place the data into the BRIGE window...
htag = findobj('Tag', 'Bridge');
if(~ishandle(htag))
    disp('Could not access Bridge window for display');
    return;
end
figure(htag); % access it...
hax = findobj('tag', 'br_graph');
if(isempty(hax))
    disp('could not find the graph in the window');
    return;
end;

fsize=7;
pts = min(size(time,2), size(v_bal,2));
plot(hax, time(:,1:pts)', v_bal(:,1:pts)');
set(gca, 'Fontsize', fsize);
set(gca, 'GridLinestyle', ':');
set(gca, 'tag', 'br_graph');
grid on;
ylabel('V (mV)');
v = get(gca, 'Xlim');
v(2)=tmax;
set(gca, 'Xlim', v);
disp('bridge_new: done');
return;
